package com.sakura.mall.ware.wareOrderTaskDetail.service.impl;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.ware.wareOrderTaskDetail.domain.entity.WareOrderTaskDetailEntity;
import com.sakura.mall.ware.wareOrderTaskDetail.domain.request.AddWareOrderTaskDetailRequest;
import com.sakura.mall.ware.wareOrderTaskDetail.domain.request.UpdateWareOrderTaskDetailRequest;
import com.sakura.mall.ware.wareOrderTaskDetail.domain.request.WareOrderTaskDetailPageRequest;
import com.sakura.mall.ware.wareOrderTaskDetail.domain.vo.WareOrderTaskDetailVo;
import com.sakura.mall.ware.wareOrderTaskDetail.mapper.WareOrderTaskDetailMapper;
import com.sakura.mall.ware.wareOrderTaskDetail.service.WareOrderTaskDetailService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 库存工作单 service impl
 *
 * @author sakura
 */
@Service
@RequiredArgsConstructor
public class WareOrderTaskDetailServiceImpl extends ServiceImpl<WareOrderTaskDetailMapper, WareOrderTaskDetailEntity> implements WareOrderTaskDetailService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(AddWareOrderTaskDetailRequest request) {
        // todo 其他校验逻辑
        WareOrderTaskDetailEntity wareOrderTaskDetail = request.convert(WareOrderTaskDetailEntity.class);
        this.save(wareOrderTaskDetail);
    }

    @Override
    public Page<WareOrderTaskDetailVo> queryPage(WareOrderTaskDetailPageRequest request) {
        IPage<WareOrderTaskDetailEntity> qp = request.toPage();
        LambdaQueryWrapper<WareOrderTaskDetailEntity> queryWrapper = new LambdaQueryWrapper<>();
        this.page(qp, queryWrapper);
        IPage<WareOrderTaskDetailVo> ret = qp.convert(entity -> entity.convert(WareOrderTaskDetailVo.class));
        return Page.convert(ret);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateById(Long id, UpdateWareOrderTaskDetailRequest request) {
        WareOrderTaskDetailEntity entity = request.convert(WareOrderTaskDetailEntity.class);
        entity.setId(id);
        this.updateById(entity);
    }

}

